Skip to content

autopoi使用模板导出时,如果在循环列后存在公式单元格,导出来后该单元格未空,公式没了 #8148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
q060831 opened this issue Apr 19, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@q060831
Copy link

q060831 commented Apr 19, 2025

版本号:3.8.0

问题描述:
org.jeecgframework.poi.util.PoiExcelTempUtil工具类漏了公式了

    /**
     * 把这N行的数据,cell重新设置下,修复因为shift的浅复制问题,导致文本不显示的错误
     *
     * @param sheet
     * @param startRow
     * @param endRow
     */
    public static void reset(Sheet sheet, int startRow, int endRow) {
        if (sheet.getWorkbook() instanceof HSSFWorkbook) {
            return;
        }
        for (int i = startRow; i <= endRow; i++) {
            Row row = sheet.getRow(i);
            if (row == null) {
                continue;
            }
            int cellNum = row.getLastCellNum();
            for (int j = 0; j < cellNum; j++) {
                if (row.getCell(j) == null) {
                    continue;
                }
                Map<String, Object> map = copyCell(row.getCell(j));
                row.removeCell(row.getCell(j));
                Cell cell = row.createCell(j);
                cell.setCellStyle((CellStyle) map.get("cellStyle"));
                if ((boolean) map.get("isDate")) {
                    cell.setCellValue((Date) map.get("value"));
                } else {
                    CellType cellType = (CellType) map.get("cellType");
                    switch (cellType) {
                        case NUMERIC:
                            cell.setCellValue((double) map.get("value"));
                            break;
                        case STRING:
                            cell.setCellValue((String) map.get("value"));
                            break;
                        case FORMULA:
                             // 这里是不是漏了这个
                             cell.setCellFormula((String) map.get("value"));
                            break;
                        case BLANK:
                            break;
                        case BOOLEAN:
                            cell.setCellValue((boolean) map.get("value"));
                        case ERROR:
                            break;
                    }
                }
            }
        }
    }
@q060831 q060831 added the bug Something isn't working label Apr 19, 2025
@q060831
Copy link
Author

q060831 commented May 6, 2025

Image
Image
Image

@zhangdaiscott
Copy link
Member

sq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants